<%--
    Document   : loancollection
    Created on : Apr 6, 2011, 3:37:32 PM
    Author     : Dine
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>
    <head>
        <sj:head jqueryui="true" jquerytheme="south-street" compressed="false"/>
        <jsp:include page="WEB-INF/fragments/globalHead.html"/>
        <title>Cashmate <s:property value="#session.branch.branchname"/></title>
        <!--main.jsp css-->

    </head>
    <body>
        <s:action name="query-privilege" executeResult="false" var="privilegeView" >
            <s:param name="privilege">v</s:param>
            <s:param name="moduleid">10</s:param>
            <s:param name="pagename">cash custodian report</s:param>
        </s:action>

        <s:action name="query-privilege" executeResult="false" var="privilegeCreate" >
            <s:param name="privilege">c</s:param>
            <s:param name="moduleid">10</s:param>
            <s:param name="pagename">cash custodian report</s:param>
        </s:action>

        <s:action name="query-privilege" executeResult="false" var="privilegeEdit" >
            <s:param name="privilege">e</s:param>
            <s:param name="moduleid">10</s:param>
            <s:param name="pagename">cash custodian report</s:param>
        </s:action>

        <s:action name="query-privilege" executeResult="false" var="privilegeDelete" >
            <s:param name="privilege">d</s:param>
            <s:param name="moduleid">10</s:param>
            <s:param name="pagename">cash custodian report</s:param>
        </s:action>

        <c:if test="${sessionScope.auth == null || sessionScope.auth == false}">
            <%--<jsp:forward page="index.jsp?auth=none"/>--%>
        </c:if>
        <s:div id="bodyContainer">
            <s:div id="logoContainer" cssClass="ui-widget-content ui-corner-all">
                <s:include value="WEB-INF/fragments/banner.jsp">
                    <s:param name="branch" value="#session.branch.branchname" />
                </s:include>
            </s:div>
            <jsp:include page="WEB-INF/fragments/top.jsp"/>
            <jsp:include page="WEB-INF/fragments/mainMenu.jsp?menu=Loan"/>
            <jsp:include page="WEB-INF/fragments/left.jsp?type=loan&innerType=ccr&select1=subMenuCCR"/>

            <s:div id="contentContainer" cssClass="ui-widget-content ui-corner-all">
                <h1 id="contentHeader" class="ui-state-default ui-corner-all"></h1>
                <s:div id="theContent">

                <style type="text/css">
                    #first label{
                        margin-right:7em;
                    }

                    #first input{
                        margin-right:5em;
                    }

                    #ccrinfo button.ui-datepicker-trigger,#ccreport button.ui-datepicker-trigger{
                        display:none;
                    }

                    #deposit,#collection,#check,#cash,#addtlfund,#bankdebit,#bankcredit{
                        overflow:auto;
                        height:125px;
                        width:950px;
                    }

                    #second input{
                        width:105px;
                    }

                    #cash input,#cash label,#addtlfund input,#addtlfund label{
                        width:130px;
                    }

                    #gview_ccrdebitGrid,#gview_ccrcreditGrid,#gview_ccrfundGrid,#gview_ccrcashGrid,#gview_collectionsGrid,#gview_ccrGrid,#gview_ccrcheckGrid,#gview_depositsGrid{
                        height:430px;
                        overflow:auto;
                    }

                    #empcode,#empname,#acctnum{
                        background-color: #ddd;
                    }


                </style>
                <s:if test="#session.branch.branchname!='Head Office'">
                    <style>
                        #deposit,#collection,#check,#cash,#addtlfund,#bankdebit,#bankcredit{
                            overflow:auto;
                            height:200px;
                            width:950px;
                        }
                        #branch{
                            background-color: #ddd;
                        }
                    </style>
                </s:if>

                <script type="text/javascript">
                    $(document).ready(function(){
                        $('h1#contentHeader').html('<span id="level1">Cash Custodian Report</span>');
                        
                        $('#dateccr').change(function(e){
                            if($('#branch').val()=="-1"){
                                alert("Pls select an area code.");
                            }else if($('#empcode').val()==""||$('#empname').val()==""||$('#acctnum').val()==""||$('#dateccr').val()==""){
                                alert("Pls complete the values for the fields.");
                            }else{
                                $('#ccrinfo').submit(); 
                            }
                        });
                        
                        $('#dateccr').val("04/19/2011")
                        $('#second input').attr("readonly", "true");
                        
                        $('#viewccr').click(function(e){
                            $('#ccrinfo').submit();
                        });
                        
                        $('#savereport').click(function(e){
                            $('#ccreport').submit(); 
                        });
                        
                        $('#disbursementcoh').val(0);
                        $('#addtlfundcoh').val(0);
                        $('#bankdebitmemocoh').val(0);
                        $('#bankcreditmemocoh').val(0);

                        $('#addcashbtn').click(function(e){
                            $('#clonecash').removeAttr("style");
                            //                            $("<tr></tr>").attr("id", "clonecash").addClass("clonecash").insertAfter($('#cashtbody'));
                            //                            $('#clonecash').append($("<td></td>").append($("<input></input>").attr("id","cashseries").css("width","50px").val("1")))
                            //                            $('#clonecash').append($("<td></td>").append($("<input></input>").attr("id","cashpayeefname").attr("name","cashpayeefname").css("width","100px")))
                            //                            $('#clonecash').append($("<td></td>").append($("<input></input>").attr("id","cashpayeemname").attr("name","cashpayeemname")))
                            //                            $('#clonecash').append($("<td></td>").append($("<input></input>").attr("id","cashpayeelname").attr("name","cashpayeelname")))
                            //                            $('#clonecash').append($("<td></td>").append($("<input></input>").attr("id","cashparticular").attr("name","cashparticular")))
                            //                            $('#clonecash').append($("<td></td>").append($("<input></input>").attr("id","cashdocnum").attr("name","cashdocnum")))
                            //                            $('#clonecash').append($("<td></td>").append($("<input></input>").attr("id","cashamount").attr("name","cashamount").addClass("cashamount")))
                            //                            $('#clonecash').append($("<td></td>").append($("<input></input>").attr("id","removebtncash").addClass("removebtn").css("width","60px").val("Remove").attr("type","button")))
                            //                            
                        });


                        //COMPUTE ENDING BALANCE
                        function computeEndbal(field){
                            var beginbalcib = parseFloat($('#beginbalcib').val());
                            var depintransitcib = parseFloat($('#depintransitcib').val());
                            var collectioncib = parseFloat($('#collectioncib').val());
                            var disbursementcib = parseFloat($('#disbursementcib').val());
                            var addtlfundcib = parseFloat($('#addtlfundcib').val());
                            var bankdebitmemocib = parseFloat($('#bankdebitmemocib').val());
                            var bankcreditmemocib = parseFloat($('#bankcreditmemocib').val());
                            var endbalcib = parseFloat($('#endbalcib').val());
                         
                            var beginbalcoh = parseFloat($('#beginbalcoh').val());
                            var depintransitcoh = parseFloat($('#depintransitcoh').val());
                            var collectioncoh = parseFloat($('#collectioncoh').val());
                            var disbursementcoh = parseFloat($('#disbursementcoh').val());
                            var addtlfundcoh = parseFloat($('#addtlfundcoh').val());
                            var bankdebitmemocoh = parseFloat($('#bankdebitmemocoh').val());
                            var bankcreditmemocoh = parseFloat($('#bankcreditmemocoh').val());
                            var endbalcoh = parseFloat($('#endbalcoh').val());
                         
                            var beginbaltotal = parseFloat($('#beginbaltotal').val());
                            var depintransittotal = parseFloat($('#depintransittotal').val());
                            var collectiontotal = parseFloat($('#collectiontotal').val());
                            var disbursementtotal = parseFloat($('#disbursementtotal').val());
                            var addtlfundtotal = parseFloat($('#addtlfundtotal').val());
                            var bankdebitmemototal = parseFloat($('#bankdebitmemototal').val());
                            var bankcreditmemototal = parseFloat($('#bankcreditmemototal').val());
                            var endbaltotal =parseFloat($('#endbaltotal').val());

                            if(field=="cib"){
                                var total = beginbalcib+depintransitcib+collectioncib-disbursementcib+addtlfundcib-bankdebitmemocib+bankcreditmemocib;
                                $('#endbalcib').val(total)
                            }else if(field=="coh"){
                                var total = beginbalcoh+depintransitcoh+collectioncoh-disbursementcoh+addtlfundcoh-bankdebitmemocoh+bankcreditmemocoh;
                                $('#endbalcoh').val(total)
                            }
                            computeTotalEndBal();
                        }
                         
                        //COMPUTE TOTAL ENDING BALANCE
                        function computeTotalEndBal(){
                            var endbalcib = parseInt($('#endbalcib').val());
                            var endbalcoh = parseInt($('#endbalcoh').val());
                            $('#endbaltotal').val(endbalcib+endbalcoh);
                        }
                       
                       
                        //COMPUTE ADDITIONAL FUNDS
                        function computeTotalFund(){
                            var length = $('.amountfund').length;
                            var sum=0;
                            var item=0;
                            for(var i=0; i<length;i++){
                                item = $('.clonefund:nth-child('.concat(i+1,')',' td input.amountfund')).val();
                                if(item!=""){
                                    sum=sum+parseFloat(item);
                                }
                            }
                            $('#addtlfundcib').val(sum);
                            $('#addtlfundtotal').val(parseFloat($('#addtlfundcib').val())+parseFloat($('#addtlfundcoh').val()))
                            computeEndbal("cib");
                        }
                        
                        //ADDITIONAL FUNDS
                        $('.amountfund').keyup(function(e){
                            computeTotalFund();
                        });
                        
                        //COMPUTE BANK DEBIT MEMO
                        function computeTotalDebit(){
                            var length = $('.amountdebit').length;
                            var sum=0;
                            var item=0;
                            for(var i=0; i<length;i++){
                                item = $('.clonedebit:nth-child('.concat(i+1,')',' td input.amountdebit')).val();
                                if(item!=""){
                                    sum=sum+parseFloat(item);
                                }                                }
                                                
                            $('#bankdebitmemocib').val(sum);
                            $('#bankdebitmemototal').val(parseFloat($('#bankdebitmemocib').val())+parseFloat($('#bankdebitmemocoh').val()))
                            computeEndbal("cib");
                        }

                        
                        //BANK DEBIT MEMO
                        $('.amountdebit').keyup(function(e){
                            computeTotalDebit();
                        });
                        
                        //COMPUTE BANK CREDIT MEMO
                        function computeTotalCredit(){
                            var length = $('.amountcredit').length;
                            var sum=0;
                            var item=0;
                            for(var i=0; i<length;i++){
                                item = $('.clonecredit:nth-child('.concat(i+1,')',' td input.amountcredit')).val();
                                if(item!=""){
                                    sum=sum+parseFloat(item);
                                }                               }
                                                
                            $('#bankcreditmemocib').val(sum);
                            $('#bankcreditmemototal').val(parseFloat($('#bankcreditmemocib').val())+parseFloat($('#bankcreditmemocoh').val()))
                            computeEndbal("cib");
                        }
                        
                        //BANK CREDIT MEMO
                        $('.amountcredit').keyup(function(e){
                            computeTotalCredit();
                        });
                        
                        
                        $('#disbursementcib').change(function(e){
                            var disbursementcib = $('#disbursementcib').val();
                            var disbursementcoh = $('#disbursementcoh').val();
                            $('#disbursementtotal').val(parseFloat(disbursementcib)+parseFloat(disbursementcoh));
                        });
                    
                        var beginbalcib=$('#beginbalcib').val();
                        var beginbalcoh=$('#beginbalcoh').val();
                        
                        if(beginbalcib!=""&&beginbalcoh!=""){
                            $('#beginbaltotal').val(parseFloat(beginbalcib)+parseFloat(beginbalcoh))
                        }
                        
                        //DELETE ROW
                        $('.removebtn').click(function(e){
                            var id=this.id;
                          
                            if(id.indexOf('removebtnfund')!=-1){
                                var num=id.substr(13);
                                var last = $('.clonefund:last').attr("id").substr(9);
                                if(id=="removebtnfund"){
                                    $('#clonefund').remove();
                                    $('.clonefund:first').attr('id','clonefund');
                                    $('.clonefund:first td:last input').attr('id','removebtnfund');      
                                    $('.clonefund:first td:first input').val(1);
                                    fundctr=1;
                                }else{
                                    $('#clonefund'.concat(num)).remove();

                                    if(num==(parseInt(last)+1)){    //last
                                        fundctr=parseInt(last)+1;
                                    }else{
                                        fundctr = parseInt(last)
                                    }
                                }
                                for(var i=1;i<last+1;i++){
                                    $('.clonefund'.concat(':nth-child('.concat(i+1,')'))).attr('id','clonefund'.concat(i));
                                    $('#clonefund'.concat(i, ' td:first')).find('input').attr('value',i+1);
                                        
                                    $('#clonefund'.concat(i, ' td:first')).find('input').attr('id','seriesfund'.concat(i));
                                    $('#clonefund'.concat(i, ' td:nth-child(2)')).find('input').attr('id','payeefundfname'.concat(i));
                                    $('#clonefund'.concat(i, ' td:nth-child(3)')).find('input').attr('id','payeefundmname'.concat(i));
                                    $('#clonefund'.concat(i, ' td:nth-child(4)')).find('input').attr('id','payeefundlname'.concat(i));
                                    $('#clonefund'.concat(i, ' td:nth-child(5)')).find('input').attr('id','particularfund'.concat(i));
                                    $('#clonefund'.concat(i, ' td:nth-child(6)')).find('input').attr('id','docnumfund'.concat(i));
                                    $('#clonefund'.concat(i, ' td:nth-child(7)')).find('input').attr('id','amountfund'.concat(i));
                                    $('#clonefund'.concat(i, ' td:last')).find('input').attr('id','removebtnfund'.concat(i));
                                }
                                computeTotalFund(); // update total
                                $('.amountfund:last').attr("id", "lastfund");
                            }else if(id.indexOf('removebtndebit')!=-1){
                                var num=id.substr(14);
                                var last = $('.clonedebit:last').attr("id").substr(10);
                                if(id=="removebtndebit"){
                                    $('#clonedebit').remove();
                                    $('.clonedebit:first').attr('id','clonedebit');
                                    $('.clonedebit:first td:last input').attr('id','removebtndebit');      
                                    $('.clonedebit:first td:first input').val(1);
                                    debitctr=1;
                                }else{
                                        
                                    $('#clonedebit'.concat(num)).remove();

                                    if(num==(parseInt(last)+1)){    //last
                                        debitctr=parseInt(last)+1;
                                    }else{
                                        debitctr = parseInt(last)
                                    }
                                }
                                for(var i=1;i<last+1;i++){
                                    $('.clonedebit'.concat(':nth-child('.concat(i+1,')'))).attr('id','clonedebit'.concat(i));
                                    $('#clonedebit'.concat(i, ' td:first')).find('input').attr('value',i+1);
                                        
                                    $('#clonedebit'.concat(i, ' td:first')).find('input').attr('id','seriesdebit'.concat(i));
                                    $('#clonedebit'.concat(i, ' td:nth-child(2)')).find('input').attr('id','particulardebit'.concat(i));
                                    $('#clonedebit'.concat(i, ' td:nth-child(3)')).find('input').attr('id','amountdebit'.concat(i));
                                    $('#clonedebit'.concat(i, ' td:last')).find('input').attr('id','removebtndebit'.concat(i));
                                }
                                computeTotalDebit();// update total
                                $('.amountdebit:last').attr("id", "lastdebit");
                                    
                            }else if(id.indexOf('removebtncredit')!=-1){
                                var num=id.substr(15);
                                var last = $('.clonecredit:last').attr("id").substr(11);
                                if(id=="removebtncredit"){
                                    $('#clonecredit').remove();
                                    $('.clonecredit:first').attr('id','clonecredit');
                                    $('.clonecredit:first td:last input').attr('id','removebtncredit');      
                                    $('.clonecredit:first td:first input').val(1);
                                    creditctr=1;
                                }else{
                                    $('#clonecredit'.concat(num)).remove();

                                    if(num==(parseInt(last)+1)){    //last
                                        creditctr=parseInt(last)+1;
                                    }else{
                                        creditctr = parseInt(last)
                                    }
                                }
                                for(var i=1;i<last+1;i++){
                                    $('.clonecredit'.concat(':nth-child('.concat(i+1,')'))).attr('id','clonecredit'.concat(i));
                                    $('#clonecredit'.concat(i, ' td:first')).find('input').attr('value',i+1);
                                        
                                    $('#clonecredit'.concat(i, ' td:first')).find('input').attr('id','seriescredit'.concat(i));
                                    $('#clonecredit'.concat(i, ' td:nth-child(2)')).find('input').attr('id','particularcredit'.concat(i));
                                    $('#clonecredit'.concat(i, ' td:nth-child(3)')).find('input').attr('id','amountcredit'.concat(i));
                                    $('#clonecredit'.concat(i, ' td:last')).find('input').attr('id','removebtncredit'.concat(i));
                                }
                                computeTotalCredit();// update total
                                $('.amountcredit:last').attr("id", "lastcredit");
                            }
                        });
                        
                        

                        //ADD ROW FOR ADDDITIONAL FUND
                        var fundctr=1;
                        $('.amountfund').bind('keypress',function(e){
                            var code= (e.keyCode ? e.keyCode : e.which);
                            if((e.type=='keypress'&&code==13&&((this.id=="lastfund")||fundctr==1))){
                                if(fundctr==1){
                                    $('#clonefund').clone(true).attr('id','clonefund'.concat(fundctr)).insertAfter($('#clonefund'));
                                    $('#clonefund td:nth-child(7)').find('input').attr('id','amountfund');
                                }else{
                                    $('#clonefund').clone(true).attr('id','clonefund'.concat(fundctr)).insertAfter($('#clonefund'.concat(fundctr-1)));
                                    $('#clonefund'.concat(fundctr-1, ' td:nth-child(7)')).find('input').attr('id','amountfund'.concat(fundctr-1));
                                }
                                $('#clonefund'.concat(fundctr, ' td')).find('input').attr('value','');
                                $('#clonefund'.concat(fundctr, ' td:first')).find('input').attr('value',fundctr+1);

                                $('#clonefund'.concat(fundctr, ' td:first')).find('input').attr('id','seriesfund'.concat(fundctr));
                                $('#clonefund'.concat(fundctr, ' td:nth-child(2)')).find('input').attr('id','payeefundfname'.concat(fundctr));
                                $('#clonefund'.concat(fundctr, ' td:nth-child(3)')).find('input').attr('id','payeefundmname'.concat(fundctr));
                                $('#clonefund'.concat(fundctr, ' td:nth-child(4)')).find('input').attr('id','payeefundlname'.concat(fundctr));
                                $('#clonefund'.concat(fundctr, ' td:nth-child(5)')).find('input').attr('id','particularfund'.concat(fundctr));
                                $('#clonefund'.concat(fundctr, ' td:nth-child(6)')).find('input').attr('id','docnumfund'.concat(fundctr));
                                $('#clonefund'.concat(fundctr, ' td:nth-child(7)')).find('input').attr('id','lastfund');
                                $('#clonefund'.concat(fundctr, ' td:last')).find('input').attr('id','removebtnfund'.concat(fundctr));
                                $('#clonefund'.concat(fundctr, ' td:last')).find('input').attr('value','Remove');
                                $('#clonefund'.concat(fundctr, ' td:nth-child(2)')).find('input').focus();
                                
                                fundctr++;
                            }
                        });
                        
                        //ADD ROW FOR BANK DEBIT MEMO
                        var debitctr=1;
                        $('.amountdebit').bind('keypress',function(e){
                            var code= (e.keyCode ? e.keyCode : e.which);
                            if((e.type=='keypress'&&code==13&&((this.id=="lastdebit")||debitctr==1))){
                                if(debitctr==1){
                                    $('#clonedebit').clone(true).attr('id','clonedebit'.concat(debitctr)).insertAfter($('#clonedebit'));
                                    $('#clonedebit td:nth-child(3)').find('input').attr('id','amountdebit');
                                }else{
                                    $('#clonedebit').clone(true).attr('id','clonedebit'.concat(debitctr)).insertAfter($('#clonedebit'.concat(debitctr-1)));
                                    $('#clonedebit'.concat(debitctr-1, ' td:nth-child(3)')).find('input').attr('id','amountdebit'.concat(debitctr-1));
                                }
                                $('#clonedebit'.concat(debitctr, ' td')).find('input').attr('value','');
                                $('#clonedebit'.concat(debitctr, ' td:first')).find('input').attr('value',debitctr+1);
                                
                                $('#clonedebit'.concat(debitctr, ' td:first')).find('input').attr('id','seriesdebit'.concat(debitctr));
                                $('#clonedebit'.concat(debitctr, ' td:nth-child(2)')).find('input').attr('id','particulardebit'.concat(debitctr));
                                $('#clonedebit'.concat(debitctr, ' td:nth-child(3)')).find('input').attr('id','lastdebit');
                                $('#clonedebit'.concat(debitctr, ' td:last')).find('input').attr('id','removebtndebit'.concat(debitctr));
                                $('#clonedebit'.concat(debitctr, ' td:last')).find('input').attr('value','Remove');
                                $('#clonedebit'.concat(debitctr, ' td:nth-child(2)')).find('input').focus();
                                debitctr++;
                            }
                        });
                      
                        //ADD ROW FOR BANK CREDIT MEMO
                        var creditctr=1;
                        $('.amountcredit').bind('keypress',function(e){
                            var code= (e.keyCode ? e.keyCode : e.which);
                            if((e.type=='keypress'&&code==13&&((this.id=="lastcredit")||creditctr==1))){
                                if(creditctr==1){
                                    $('#clonecredit').clone(true).attr('id','clonecredit'.concat(creditctr)).insertAfter($('#clonecredit'));
                                    $('#clonecredit td:nth-child(3)').find('input').attr('id','amountcredit');

                                }else{
                                    $('#clonecredit').clone(true).attr('id','clonecredit'.concat(creditctr)).insertAfter($('#clonecredit'.concat(creditctr-1)));
                                    $('#clonecredit'.concat(creditctr-1, ' td:nth-child(3)')).find('input').attr('id','amountcredit'.concat(creditctr));
                                }
                                $('#clonecredit'.concat(creditctr, ' td')).find('input').attr('value','');
                                $('#clonecredit'.concat(creditctr, ' td:first')).find('input').attr('value',creditctr+1);
                                $('#clonecredit'.concat(creditctr, ' td:first')).find('input').attr('id','seriescredit'.concat(creditctr));
                                $('#clonecredit'.concat(creditctr, ' td:nth-child(2)')).find('input').attr('id','particularcredit'.concat(creditctr));
                                $('#clonecredit'.concat(creditctr, ' td:nth-child(3)')).find('input').attr('id','lastcredit');
                                $('#clonecredit'.concat(creditctr, ' td:last')).find('input').attr('id','removebtncredit'.concat(creditctr));
                                $('#clonecredit'.concat(creditctr, ' td:last')).find('input').attr('value','Remove');
                                $('#clonecredit'.concat(creditctr, ' td:nth-child(2)')).find('input').focus();
                                
                                creditctr++;
                            }
                        });
                        
                        
                        
                        //ADDITIONAL FUNDS NAVIGATION
                        $('.clonefund').keypress(function(e){
                            var code= (e.keyCode ? e.keyCode : e.which);
                            if(code==13){
                                var id = e.target.id;
                                if(id.indexOf("payeefundfname")!="-1"){
                                    var num = id.substr(14);
                                    $('#payeefundmname'.concat(num)).focus();
                                }else if(id.indexOf("payeefundmname")!="-1"){
                                    var num = id.substr(14);
                                    $('#payeefundlname'.concat(num)).focus();
                                }else if(id.indexOf("payeefundlname")!="-1"){
                                    var num = id.substr(14);
                                    $('#particularfund'.concat(num)).focus();
                                }else if(id.indexOf("particularfund")!="-1"){
                                    var num = id.substr(14);
                                    $('#docnumfund'.concat(num)).focus();
                                }else if(id.indexOf("docnumfund")!="-1"){
                                    var num = id.substr(10);
                                    if(fundctr==1){
                                        $('#amountfund').focus();
                                    }else if(fundctr-1 ==num){
                                        $('#lastfund').focus();
                                    }else{
                                        $('#amountfund'.concat(num)).focus();
                                    }                                }
                            }
                        });
                        
                        //BANK DEBIT MEMO NAVIGATION
                        $('.clonedebit').keypress(function(e){
                            var code= (e.keyCode ? e.keyCode : e.which);
                            if(code==13){
                                var id = e.target.id;
                                if(id.indexOf("particulardebit")!="-1"){
                                    var num = id.substr(15);
                                    if(debitctr==1){
                                        $('#amountdebit').focus();
                                    }else if(debitctr-1 ==num){
                                        $('#lastdebit').focus();
                                    }else{
                                        $('#amountdebit'.concat(num)).focus();
                                    }                                           }
                            }
                        });
                        
                        //BANK CREDIT MEMO NAVIGATION
                        $('.clonecredit').keypress(function(e){
                            var code= (e.keyCode ? e.keyCode : e.which);
                            if(code==13){
                                var id = e.target.id;
                                if(id.indexOf("particularcredit")!="-1"){
                                    var num = id.substr(16);
                                    if(creditctr==1){
                                        $('#amountcredit').focus();
                                    }else if(creditctr-1 ==num){
                                        $('#lastcredit').focus();
                                    }else{
                                        $('#amountcredit'.concat(num)).focus();
                                    }                                      }
                            }
                        });
                        
                        $('#depositslipnum').keypress(function(e){
                            var code= (e.keyCode ? e.keyCode : e.which);
                            if(code==13){
                                $('#datedeposit').focus();
                            }
                        });
                        
                        $('#datedeposit').keypress(function(e){
                            var code= (e.keyCode ? e.keyCode : e.which);
                            if(code==13){
                                $('#depositamount').focus();
                            }
                        });
                        
                    });
                </script>

                <c:if test="${param.cat == 'savedccr'}">
                    <script type="text/javascript">
                        $(document).ready(function(){
                            $('.removebtn').click(function(e){
                                var id=this.id;
                               
                                if(id.indexOf('removebtncash')!=-1){
                                    var num=id.substr(13);
                                    var last = $('.clonecash:last').attr("id").substr(9);
                                    if(id=="removebtncash"){
                                        $('#clonecash').remove();
                                        $('.clonecash:first').attr('id','clonecash');
                                        $('.clonecash:first td:last input').attr('id','removebtncash');      
                                        $('.clonecash:first td:first input').val(1);
                                        cashctr=1;
                                    }else{
                                        $('#clonecash'.concat(num)).remove();

                                        if(num==(parseInt(last)+1)){    //last
                                            cashctr=parseInt(last)+1;
                                        }else{
                                            cashctr = parseInt(last)
                                        }
                                    }
                                    for(var i=1;i<last+1;i++){
                                        $('.clonecash'.concat(':nth-child('.concat(i+1,')'))).attr('id','clonecash'.concat(i));
                                        $('#clonecash'.concat(i, ' td:first')).find('input').attr('value',i+1);
                                        
                                        $('#clonecash'.concat(i, ' td:first')).find('input').attr('id','cashseries'.concat(i));
                                        $('#clonecash'.concat(i, ' td:nth-child(2)')).find('input').attr('id','cashpayeefname'.concat(i));
                                        $('#clonecash'.concat(i, ' td:nth-child(3)')).find('input').attr('id','cashpayeemname'.concat(i));
                                        $('#clonecash'.concat(i, ' td:nth-child(4)')).find('input').attr('id','cashpayeelname'.concat(i));
                                        $('#clonecash'.concat(i, ' td:nth-child(5)')).find('input').attr('id','cashparticular'.concat(i));
                                        $('#clonecash'.concat(i, ' td:nth-child(6)')).find('input').attr('id','cashdocnum'.concat(i));
                                        $('#clonecash'.concat(i, ' td:last')).find('input').attr('id','removebtncash'.concat(i));
                                    }
                                    $('.cashamount:last').attr("id", "lastcash");
                                }
                            });
                            
                            var cashctr=$('.clonecash').length;
                            for(var i=0;i<cashctr;i++){
                                if(i>=1){
                                    $('.clonecash'.concat(':nth-child('.concat(i+1,')'))).attr('id','clonecash'.concat(i));    
                                    $('.clonecash'.concat(':nth-child('.concat(i+1,')'),' td:last input')).attr('id','removebtncash'.concat(i));
                                }
                                $('.clonecash'.concat(':nth-child('.concat(i+1,')'),' td:first input')).val(i+1);                  
                            }
                            
                            $('.cashamount').bind('keypress',function(e){
                                var code= (e.keyCode ? e.keyCode : e.which);
                                if((e.type=='keypress'&&code==13&&((this.id=="lastcash")||this.id=="cashfirst"))){
                                    if(cashctr==1){
                                        $('#clonecash').clone(true).attr('id','clonecash'.concat(cashctr)).insertAfter($('#clonecash'));
                                        $('#clonecash td:nth-child(7)').find('input').attr('id','cashamount');
                                    }else{
                                        for(var i=1;i<cashctr;i++){
                                            $('.clonecash'.concat(':nth-child('.concat(i+1,')'))).attr('id','clonecash'.concat(i));                  
                                            $('.clonecash'.concat(':nth-child('.concat(i+1,')'),' td:last input')).attr('id','removebtncash'.concat(i));                  
                                        }
                                        $('#clonecash').clone(true).attr('id','clonecash'.concat(cashctr)).insertAfter($('.clonecash:last'));
                                        $('#clonecash'.concat(cashctr-1, ' td:nth-child(7)')).find('input').attr('id','cashamount'.concat(cashctr-1));
                                    }
                                    $('#clonecash'.concat(cashctr, ' td')).find('input').attr('value','');
                                    $('#clonecash'.concat(cashctr, ' td:first')).find('input').attr('value',cashctr+1);
                                    
                                    $('#clonecash'.concat(cashctr, ' td:first')).find('input').attr('id','cashseries'.concat(cashctr));
                                    $('#clonecash'.concat(cashctr, ' td:nth-child(2)')).find('input').attr('id','cashpayeefname'.concat(cashctr));
                                    $('#clonecash'.concat(cashctr, ' td:nth-child(3)')).find('input').attr('id','cashpayeemname'.concat(cashctr));
                                    $('#clonecash'.concat(cashctr, ' td:nth-child(4)')).find('input').attr('id','cashpayeelname'.concat(cashctr));
                                    $('#clonecash'.concat(cashctr, ' td:nth-child(5)')).find('input').attr('id','cashparticular'.concat(cashctr));
                                    $('#clonecash'.concat(cashctr, ' td:nth-child(6)')).find('input').attr('id','cashdocnum'.concat(cashctr));
                                    $('#clonecash'.concat(cashctr, ' td:nth-child(7)')).find('input').attr('id','lastcash');
                                    $('#clonecash'.concat(cashctr, ' td:last')).find('input').attr('id','removebtncash'.concat(cashctr));
                                    $('#clonecash'.concat(cashctr, ' td:last')).find('input').attr('value','Remove');
                                    $('#clonecash'.concat(cashctr, ' td:nth-child(2)')).find('input').focus();
                                
                                    cashctr++;
                                }
                            });
                            
                            
                            var fundctr=$('.clonefund').length;
                            for(var i=0;i<fundctr;i++){
                                if(i>=1){
                                    $('.clonefund'.concat(':nth-child('.concat(i+1,')'))).attr('id','clonefund'.concat(i));    
                                    $('.clonefund'.concat(':nth-child('.concat(i+1,')'),' td:last input')).attr('id','removebtnfund'.concat(i));
                                }
                                $('.clonefund'.concat(':nth-child('.concat(i+1,')'),' td:first input')).val(i+1);                  
                            }
                            $('.amountfund').bind('keypress',function(e){
                                var code= (e.keyCode ? e.keyCode : e.which);
                                if((e.type=='keypress'&&code==13&&((this.id=="lastfund")||this.id=="firstfund"))){
                                    if(fundctr==1){
                                        $('#clonefund').clone(true).attr('id','clonefund'.concat(fundctr)).insertAfter($('#clonefund'));
                                        $('#clonefund td:nth-child(7)').find('input').attr('id','amountfund');

                                    }else{
                                        for(var i=1;i<fundctr;i++){
                                            $('.clonefund'.concat(':nth-child('.concat(i+1,')'))).attr('id','clonefund'.concat(i));
                                            $('.clonefund'.concat(':nth-child('.concat(i+1,')'),' td:last input')).attr('id','removebtnfund'.concat(i));                  
                                        }
                                        $('#clonefund').clone(true).attr('id','clonefund'.concat(fundctr)).insertAfter($('.clonefund:last'));
                                        $('#clonefund'.concat(fundctr-1, ' td:nth-child(7)')).find('input').attr('id','amountfund'.concat(fundctr-1));
                                    }
                                    $('#clonefund'.concat(fundctr, ' td')).find('input').attr('value','');
                                    $('#clonefund'.concat(fundctr, ' td:first')).find('input').attr('value',fundctr+1);

                                    $('#clonefund'.concat(fundctr, ' td:first')).find('input').attr('id','seriesfund'.concat(fundctr));
                                    $('#clonefund'.concat(fundctr, ' td:nth-child(2)')).find('input').attr('id','payeefundfname'.concat(fundctr));
                                    $('#clonefund'.concat(fundctr, ' td:nth-child(3)')).find('input').attr('id','payeefundmname'.concat(fundctr));
                                    $('#clonefund'.concat(fundctr, ' td:nth-child(4)')).find('input').attr('id','payeefundlname'.concat(fundctr));
                                    $('#clonefund'.concat(fundctr, ' td:nth-child(5)')).find('input').attr('id','particularfund'.concat(fundctr));
                                    $('#clonefund'.concat(fundctr, ' td:nth-child(6)')).find('input').attr('id','docnumfund'.concat(fundctr));
                                    $('#clonefund'.concat(fundctr, ' td:nth-child(7)')).find('input').attr('id','lastfund');
                                    $('#clonefund'.concat(fundctr, ' td:last')).find('input').attr('id','removebtnfund'.concat(fundctr));
                                    $('#clonefund'.concat(fundctr, ' td:last')).find('input').attr('value','Remove');
                                    $('#clonefund'.concat(fundctr, ' td:nth-child(2)')).find('input').focus();

                                    $('#clonefund'.concat(fundctr, ' td:nth-child(2)')).find('input').focus();
                                
                                    fundctr++;
                                }
                            });
                            
                            var debitctr=$('.clonedebit').length;
                            for(var i=0;i<debitctr;i++){
                                if(i>=1){
                                    $('.clonedebit'.concat(':nth-child('.concat(i+1,')'))).attr('id','clonedebit'.concat(i));    
                                    $('.clonedebit'.concat(':nth-child('.concat(i+1,')'),' td:last input')).attr('id','removebtndebit'.concat(i));
                                }
                                $('.clonedebit'.concat(':nth-child('.concat(i+1,')'),' td:first input')).val(i+1);                  
                            }
                            $('.amountdebit').bind('keypress',function(e){
                                var code= (e.keyCode ? e.keyCode : e.which);
                                if((e.type=='keypress'&&code==13&&((this.id=="lastdebit")||this.id=="firstdebit"))){
                                    if(debitctr==1){
                                        $('#clonedebit').clone(true).attr('id','clonedebit'.concat(debitctr)).insertAfter($('#clonedebit'));
                                        $('#clonedebit td:nth-child(3)').find('input').attr('id','amountdebit');

                                    }else{
                                        for(var i=1;i<debitctr;i++){
                                            $('.clonedebit'.concat(':nth-child('.concat(i+1,')'))).attr('id','clonedebit'.concat(i));    
                                            $('.clonedebit'.concat(':nth-child('.concat(i+1,')'),' td:last input')).attr('id','removebtndebit'.concat(i));                  
                                        }
                                        $('#clonedebit').clone(true).attr('id','clonedebit'.concat(debitctr)).insertAfter($('.clonedebit:last'));
                                        $('#clonedebit'.concat(debitctr-1, ' td:nth-child(3)')).find('input').attr('id','amountdebit'.concat(debitctr-1));
                                    }
                                    $('#clonedebit'.concat(debitctr, ' td')).find('input').attr('value','');
                                    $('#clonedebit'.concat(debitctr, ' td:first')).find('input').attr('value',debitctr+1);
                                
                                    $('#clonedebit'.concat(debitctr, ' td:first')).find('input').attr('id','seriesdebit'.concat(debitctr));
                                    $('#clonedebit'.concat(debitctr, ' td:nth-child(2)')).find('input').attr('id','particulardebit'.concat(debitctr));
                                    $('#clonedebit'.concat(debitctr, ' td:nth-child(3)')).find('input').attr('id','lastdebit');
                                    $('#clonedebit'.concat(debitctr, ' td:last')).find('input').attr('id','removebtndebit'.concat(debitctr));
                                    $('#clonedebit'.concat(debitctr, ' td:last')).find('input').attr('value','Remove');
                                    $('#clonedebit'.concat(debitctr, ' td:nth-child(2)')).find('input').focus();

                                    $('#clonedebit'.concat(debitctr, ' td:nth-child(2)')).find('input').focus();
                                
                                    debitctr++;
                                }
                            });
                            
                            var creditctr=$('.clonecredit').length;
                            for(var i=0;i<creditctr;i++){
                                if(i>=1){
                                    $('.clonecredit'.concat(':nth-child('.concat(i+1,')'))).attr('id','clonecredit'.concat(i));    
                                    $('.clonecredit'.concat(':nth-child('.concat(i+1,')'),' td:last input')).attr('id','removebtncredit'.concat(i));
                                }
                                $('.clonecredit'.concat(':nth-child('.concat(i+1,')'),' td:first input')).val(i+1);                  
                            }
                            $('.amountcredit').bind('keypress',function(e){
                                var code= (e.keyCode ? e.keyCode : e.which);
                                if((e.type=='keypress'&&code==13&&((this.id=="lastcredit")||this.id=="firstcredit"))){
                                    if(creditctr==1){
                                        $('#clonecredit').clone(true).attr('id','clonecredit'.concat(creditctr)).insertAfter($('#clonecredit'));
                                        $('#clonecredit td:nth-child(3)').find('input').attr('id','amountcredit');

                                    }else{
                                        for(var i=1;i<creditctr;i++){
                                            $('.clonecredit'.concat(':nth-child('.concat(i+1,')'))).attr('id','clonecredit'.concat(i));                  
                                            $('.clonecredit'.concat(':nth-child('.concat(i+1,')'),' td:last input')).attr('id','removebtncredit'.concat(i));                  
                                        }
                                        $('#clonecredit').clone(true).attr('id','clonecredit'.concat(creditctr)).insertAfter($('.clonecredit:last'));
                                        $('#clonecredit'.concat(creditctr-1, ' td:nth-child(3)')).find('input').attr('id','amountcredit'.concat(creditctr));
                                    }
                                    $('#clonecredit'.concat(creditctr, ' td')).find('input').attr('value','');
                                    $('#clonecredit'.concat(creditctr, ' td:first')).find('input').attr('value',creditctr+1);
                         
                                    $('#clonecredit'.concat(creditctr, ' td:first')).find('input').attr('id','seriescredit'.concat(creditctr));
                                    $('#clonecredit'.concat(creditctr, ' td:nth-child(2)')).find('input').attr('id','particularcredit'.concat(creditctr));
                                    $('#clonecredit'.concat(creditctr, ' td:nth-child(3)')).find('input').attr('id','lastcredit');
                                    $('#clonecredit'.concat(creditctr, ' td:last')).find('input').attr('id','removebtncredit'.concat(creditctr));
                                    $('#clonecredit'.concat(creditctr, ' td:last')).find('input').attr('value','Remove');
                                    $('#clonecredit'.concat(creditctr, ' td:nth-child(2)')).find('input').focus();

                                    $('#clonecredit'.concat(creditctr, ' td:nth-child(2)')).find('input').focus();
                                
                                    creditctr++;
                                }
                            });
                        });
                    </script>
                    <jsp:include page="WEB-INF/fragments/savedccr.jsp"/>
                </c:if>
                <c:if test="${param.cat != 'savedccr'}">
                    <jsp:include page="WEB-INF/fragments/ccrcontent.jsp"/>
                </c:if>
                <%--  <c:if test="${param.cat == 'allccr'}">
                    <jsp:include page="WEB-INF/fragments/allccr.jsp"/>
                </c:if>
                <c:if test="${param.cat == 'alldebit'}">
                    <jsp:include page="WEB-INF/fragments/allccrdebit.jsp"/>
                </c:if>
                <c:if test="${param.cat == 'allcredit'}">
                    <jsp:include page="WEB-INF/fragments/allccrcredit.jsp"/>
                </c:if>
                <c:if test="${param.cat == 'allchecks'}">
                    <jsp:include page="WEB-INF/fragments/allccrcheck.jsp"/>
                </c:if>
                <c:if test="${param.cat == 'allcash'}">
                    <jsp:include page="WEB-INF/fragments/allccrcash.jsp"/>
                </c:if>
                <c:if test="${param.cat == 'allfund'}">
                    <jsp:include page="WEB-INF/fragments/allccrfund.jsp"/>
                </c:if>
                <c:if test="${param.cat == 'allcoll'}">
                    <jsp:include page="WEB-INF/fragments/headofficecollection.jsp"/>
                </c:if>
                <c:if test="${param.cat == 'alldeposit'}">
                    <jsp:include page="WEB-INF/fragments/headofficedeposit.jsp"/>
                </c:if>--%>

            </s:div>
        </s:div>
        <jsp:include page="WEB-INF/fragments/bottom.jsp"/>
    </s:div>
</body>
</html>
